package com.health.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.health.R;
import com.health.db.FDbManager;
import com.health.fragment.jtys.JTYSDA;
import com.health.model.LvYueFuWuBean;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tools.GlobalConts;
import com.health.tools.PopData;
import com.health.viewscontrols.qyinfo.QYInfo;
import com.health.widget.LabelsView;

import java.util.HashMap;
import java.util.List;

/**
 * 履约listAdapter
 * Created by John on 2019/3/5.
 */

public class LvYueListAdapter extends BaseAdapter {
    private List<LvYueFuWuBean> list;
    Context content;
    private GridView gd_da;private HashMap<Integer, View> viewMap = new HashMap<>();


    public LvYueListAdapter(List<LvYueFuWuBean> list,Context content,GridView gd_da){
        this.content=content;
        this.gd_da=gd_da;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (!viewMap.containsKey(position) || viewMap.get(position) == null) {
            holder = new ViewHolder();
            convertView = View.inflate(content, R.layout.item_lvyue, null);

            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.age = (TextView) convertView.findViewById(R.id.age);
            holder.lvyue_time = (TextView) convertView.findViewById(R.id.lvyue_time);

            convertView.setTag(holder);
            viewMap.put(position, convertView);

        } else {
            convertView = viewMap.get(position);
            holder = (ViewHolder) convertView.getTag();
        }

        if (viewMap.size() > 20) {
            synchronized (convertView) {
                for (int i = 1; i < gd_da.getFirstVisiblePosition() - 3; i++) {
                    viewMap.remove(i);
                }
                for (int i = gd_da.getLastVisiblePosition() + 3; i < getCount(); i++) {
                    viewMap.remove(i);
                }
            }
        }

        setData(holder, position, convertView);

        return convertView;
    }

    /**
     * 设置数据
     *
     * @author 王婷婷
     * @date 2017年4月8日 上午9:30:07
     */
    private void setData(ViewHolder holder, int position, View convertView) {

        final LvYueFuWuBean info = list.get(position);
        Log.e("adapter---", info.toString());

        holder.name.setText("姓名:"+info.getName());
        holder.age.setText("年龄:"+info.getAge());





        holder.lvyue_time.setText("服务时间:"+info.getLvyueDate());



    }


    private class ViewHolder {

        TextView name;// 姓名

        TextView age;// 年龄
        TextView lvyue_time;

    }
}
